﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace Bes.Swsp.ToolBox
{
  public class ToolBoxButton : ESRI.ArcGIS.Desktop.AddIns.Button
  {
    ApplicationWindow _appWindow = null;
    private ToolBoxForm _toolBoxForm = null;

    public ToolBoxButton()
    {
      _appWindow = new ApplicationWindow(ArcMap.Application.hWnd);
    }

    protected override void OnClick()
    {
      try
      {
        ArcMap.Application.CurrentTool = null;
        if (_toolBoxForm == null || _toolBoxForm.IsDisposed)
        {
          _toolBoxForm = new ToolBoxForm(ToolBoxExtension.Extension.Settings);
        }
        if (!_toolBoxForm.Visible)
        {
          _toolBoxForm.Show(_appWindow);
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(_appWindow, ex.GetType().FullName + ": " + ex.Message, this.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
    }

    protected override void OnUpdate()
    {
      Enabled = ArcMap.Application != null;
    }
  }
}
